#pragma once
template<class T>
class my_less
{
public:
    bool operator()(const T& a, const T& b)
    {
        return a < b;
    }
};

template<class T>
class my_greater
{
public:
    bool operator()(const T& a, const T& b)
    {
        return a > b;
    }
};
namespace czy
{
    template <class T, class Container = vector<T>, class Compare = my_less<T> >
    class priority_queue

    {
    public:
        void addjustdown(int parent)
        {
            int child = 2 * parent + 1;
            while (child < c.size())
            {
                if (child + 1 < c.size() && comp(c[child], c[child+1]))
                {
                    child++;
                }
                if (comp(c[parent], c[child]))
                {
                    swap(c[parent], c[child]);
                    parent = child;
                    child = 2 * parent + 1;
                }
                else
                {
                    break;
                }
            }  
        }
        void addjustup(int child)
        {
            int parent = (child - 1) / 2;
            while (child >= 0)
            {
                if (comp(c[parent], c[child]))
                {
                    swap(c[parent], c[child]);
                    child = parent;
                    parent = (child - 1) / 2;
                }
                else
                {
                    break;
                }
            }
        }
        priority_queue()
        {
        }
        template <class InputIterator>
        priority_queue(InputIterator first, InputIterator last)
        {
            while (first!=last)
            {
                push(*first);
                ++first;
            }
        }
        bool empty() const
        {
            return c.empty();
        }
        size_t size() const
        {
            return c.size();
        }
       const T& top() const
        {
            return c.front();
        }
        void push(const T& x)
        {
            c.push_back(x);
            addjustup(c.size()-1);
        }
        void pop()
        {
            swap(c[0], c[c.size() - 1]);
            c.pop_back();
            addjustdown(0);
        }

    private:
        Container c;
        Compare comp;
    };

};